<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改工程项目支付')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fk-edit" th:object="${gcFk}">
        	<h4 class="form-header h4">基本信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <input type="hidden" name="gcProjectid" id="gcProjectid" th:value="*{gcProjectid}">
        	<input type="hidden" name="projectId" id="projectId" th:value="*{projectId}">
        	<input type="hidden" name="orderNo" id="orderNo" th:value="*{orderNo}">
        	<input type="hidden" name="xmtype" id="xmtype" th:value="*{xmtype}">
        	<input name="fpjine" type="hidden" th:value="${fpjine}" >
        	<input name="ljzf" type="hidden" th:value="${kucljzf}" >
            <div class="form-group">    
                <label class="col-sm-1 control-label is-required">项目编号：</label>
                <div class="col-sm-2">
                    <input name="projectNo" th:field="*{projectNo}" class="form-control" type="text" autoComplete="off" readonly="readonly" required>
                </div>
                <label class="col-sm-1 control-label is-required">项目负责人：</label>
                <div class="col-sm-2">
                    <input name="xmfzr" th:field="*{xmfzr}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>
                <label class="col-sm-1 control-label is-required">合同金额：</label>
                <div class="col-sm-2">
                    <input name="htzje" th:field="*{htzje}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>
                <label class="col-sm-1 control-label is-required">发票类型：</label>
                <div class="col-sm-2">
                	<input name="fpType" class="form-control" required type="text" autoComplete="off" th:field="*{fpType}" readonly="readonly">
                </div>
            </div>
            <div class="form-group">  
            	<label class="col-sm-1 control-label is-required">项目名称：</label>
                <div class="col-sm-5">
                    <input name="xmmc" th:field="*{xmmc}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>  
            	<label class="col-sm-1 control-label is-required">单位名称：</label>
                <div class="col-sm-5">
                	<input name="ckdw" class="form-control" required type="text" autoComplete="off" th:field="*{ckdw}" readonly="readonly">
                </div>
			</div>
            <h4 class="form-header h4">表单项
            	<button th:if="${gcFk.status} eq 0" type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                <button th:if="${gcFk.status} eq 0" type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
            </h4>
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button th:if="${gcFk.status} eq 0" type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button th:if="${gcFk.status} eq 2" type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button th:if="${gcFk.status} eq 4" type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:src="@{/ruoyi/base64.min.js?v=20231208}"></script>
    <script th:src="@{/js/jquery.tmpl.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "gcgl/fk";
        $("#form-fk-edit").validate({
            focusCleanup: true
        });
        
        $(function() {
        	var zlwj = $("#zlwj").val();
//         	var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(zlwj));
        	var url = zlwj;
        	$("#zlwjlink").attr("href",url);
        });

        function submitHandler() {
            if ($.validate.form()) {
            	
            	var form = document.getElementById("form-fk-edit");
                var file = new FormData(form);
                $.ajax({
                    url: "/gcgl/fk/editSave",
                    type: "POST",
                    processData:false,
                    contentType:false,
                  	//重要部分，data的传的是整个表单，不用大括号包裹；不用自定义变量名
                    data:file,
                    success: function (data) {
                    	$.operate.saveReload(data);
                    },
                    error: function (data) {
                    	$.operate.saveReload(data);
                    }
                })
            	
                //$.operate.save(prefix + "/edit", $('#form-fk-edit').serialize());
            }
        }

        $("input[name='riq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
        	var data = [[${gcFk.items}]];
        	
	    	// 初始化数据, 可以由后台传过来
		    var options = {
		    	data: data,
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
		        columns: [
		        {
		        	field: 'index',
		        	align: 'center',
		        	title: "序号",
		        	width: 50,
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	var columnId = $.common.sprintf("<input type='hidden' name='items[%s].xuh' value='%s'>", index, row.id);
                    	return columnIndex + $.table.serialNumber(index) + columnId;
                    }
                },
		        {
		            field: 'descs',
		            align: 'center',
		            title: '支付事项摘要说明',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control descscount' type='text' autoComplete='off' name='items[%s].descs' value='%s'>", index, value);
		        		return html;
                    }
		        },
// 		        {
// 		            field: 'fpType',
// 		            align: 'center',
// 		            title: '发票类型',
// 		            width: '100',
// 		            formatter: function(value, row, index) {
// 		        		var data = [{ index: index, type: value }];
// 		                return $("#itemFp").tmpl(data).html();
//                     }
// 		        },
// 		        {
// 		            field: 'fpsl',
// 		            align: 'center',
// 		            title: '发票税率',
// 		            width: '100',
// 		            formatter: function(value, row, index) {
// 		        		var data = [{ index: index, type: value }];
// 		                return $("#itemSuilv").tmpl(data).html();
//                     }
// 		        },
// 		        {
// 		            field: 'fangshi',
// 		            align: 'center',
// 		            title: '支付方式',
// 		            width: 200,
// 		            formatter: function(value, row, index) {
// 		        		var data = [{ index: index, type: value }];
// 		                return $("#itemType").tmpl(data).html();
//                     }
// 		        },
		        {
		            field: 'jine',
		            align: 'center',
		            title: '支付金额',
		            width: 280,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control jinecount' type='text' autoComplete='off' name='items[%s].jine' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'memo',
		            align: 'center',
		            title: '备注',
		            width: 280,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control memocount' type='text' autoComplete='off' name='items[%s].memo' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
                    title: '操作',
                    align: 'center',
                    width: 50,
                    formatter: function(value, row, index) {
                    	var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
		    };
		    $.table.init(options);
		});
        
        $.validator.addMethod("descscount", function(value, element) {
            return !this.optional(element);
        }, "支付事项摘要说明必填。");
        $.validator.addMethod("jinecount", function(value, element) {
            return !this.optional(element) && (value <= 10000000 && value >= 1);
        }, "支付金额长度区间1-10000000。");
        $.validator.addMethod("fangshicount", function(value, element) {
            return !this.optional(element);
        }, "支付方式必填。");
        
        function addRow() {
        	var count = $("#" + table.options.id).bootstrapTable('getData').length;
        	var row = {
                index: $.table.serialNumber(count),
                descs: "",
                jine: 0,
                fangshi: "",
                memo: "",
            }
        	sub.addRow(row);
        }
    </script>
</body>
</html>

<!-- 成本类型 -->
<script id="itemType" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].fangshi'>
    <option value="电汇" {{if type==="电汇"}}selected{{/if}}>电汇</option>
<option value="现金" {{if type==="现金"}}selected{{/if}}>现金</option>
<option value="承兑" {{if type==="承兑"}}selected{{/if}}>承兑</option>
<option value="转账" {{if type==="转账"}}selected{{/if}}>转账</option>
<option value="其他" {{if type==="其他"}}selected{{/if}}>其他</option>
</select>
</div>
</script>

<!-- 发票类型 -->
<script id="itemFp" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].fpType'>
	<option value="专用发票" {{if type==="专用发票"}}selected{{/if}}>专用发票</option>
    <option value="普通发票" {{if type==="普通发票"}}selected{{/if}}>普通发票</option>
<option value="其他选项" {{if type==="其他选项"}}selected{{/if}}>其他选项</option>
</select>
</div>
</script>

<!-- 税率 -->
<script id="itemSuilv" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].fpsl'>
    <option value="13" {{if type==="13"}}selected{{/if}}>13%</option>
	<option value="11" {{if type==="11"}}selected{{/if}}>11%</option>
	<option value="9" {{if type==="9"}}selected{{/if}}>9%</option>
	<option value="6" {{if type==="6"}}selected{{/if}}>6%</option>
	<option value="3" {{if type==="3"}}selected{{/if}}>3%</option>
	<option value="1" {{if type==="1"}}selected{{/if}}>1%</option>
	<option value="0" {{if type==="0"}}selected{{/if}}>0%</option>
</select>
</div>
</script>